package com.yunji.cabinet.dao.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yunji.cabinet.dao.IUpgradeFileDao;
import com.yunji.cabinet.domain.UpgradeFileDO;
import com.yunji.cabinet.mapper.UpgradeFileMapper;
import com.yunji.cabinet.params.CabinetVersionParam;
import com.yunji.common.base.BaseDaoImpl;
import com.yunji.common.utils.bean.BeanUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class UpgradeFileDaoImpl extends BaseDaoImpl<UpgradeFileMapper, UpgradeFileDO> implements IUpgradeFileDao {
    @Override
    public List<UpgradeFileDO> search(CabinetVersionParam param) {
        return pageList(param,new LambdaQueryWrapper<UpgradeFileDO>()
                .eq(BeanUtils.isNotNull(param.getFileId()), UpgradeFileDO::getFileId, param.getFileId())
                .eq(BeanUtils.isNotNull(param.getVersion()), UpgradeFileDO::getVersion, param.getVersion())
                .eq(BeanUtils.isNotNull(param.getFileName()), UpgradeFileDO::getFileName, param.getFileName())
                .eq(BeanUtils.isNotNull(param.getChipType()), UpgradeFileDO::getChipType, param.getChipType())
                .orderByDesc(UpgradeFileDO::getVersion));
    }

    @Override
    public boolean checkUniqueName(Long fileId, String fileName) {
        return lambdaQuery().eq(UpgradeFileDO::getFileName,fileName).ne(BeanUtils.isNotNull(fileId), UpgradeFileDO::getFileId,fileId).exists();
    }

}
